<?php

function showTable_5($n5, $n4, $n3, $n2, $n1)
{
    $tempStr = "<td style=\"border-left-width:4px;\">{$n5}</td><td>{$n4}</td><td>{$n3}</td><td>{$n2}</td><td style=\"border-right-width:4px;\">{$n1}</td>";
    return $tempStr;
}

function showTable_8h($n1, $n2, $n3, $n4, $n5, $n6)
{
    $tempStr = "<td style=\"border-left-width:4px;\">{$n1}</td><td>{$n2}</td><td>{$n3}</td><td>{$n4}</td><td>{$n5}</td><td style=\"border-right-width:4px;\">{$n6}</td>";
    return $tempStr;
}

function showTable_two_5($n1, $n2)
{
    $tempStr = "<td style=\"border-left-width:4px;\">{$n1}</td><td>{$n2}</td>";
    return $tempStr;
}

function show_total_8h($n1, $n2, $n3, $n4, $n5)
{
    $tempStr = "<td style=\"border-left-width:4px;\">{$n1}</td><td>{$n2}</td><td>{$n3}</td><td>{$n4}</td><td>{$n5}</td>";
    return $tempStr;
}

if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
require_once( "class_3d/CheckMode_3d.php" );
$gametype = intval(getvar("gametype"));
$chk = new CheckMode_3d($curruser['acl'], 5, $gametype);
$chk->checkShow3dPage();
$show3D3S = $chk->show3D3S;
unset($chk);
$tbl = $g_gametype_3d[$gametype]['en'];
$tblName = $g_gametype_3d[$gametype]['ch'];
require_once( "class_3d/MyLotto_3d.php" );
require_once( "class_5h/MyLotto_5h.php" );
$MyLotto_3d = new MyLotto_3d($gametype);
$MyLotto_5h = new MyLotto_5h($gametype);
$ui = new UI_3D(true);
$tpl = new Template2();
$page = getvar("page");
$page = $page == "" ? 1 : intval($page);
$ymdhis = date("Y-m-d H:i:s");
switch ($gametype)
{
    case 20 :
        $rs = $MyLotto_5h->getDataList3s($page, 10, $show3D3S);
        $showOpenTime = true;
        break;
    case 21 :
    case 22 :
    case 23 :
    case 24 :
        $rs = $MyLotto_5h->getDataList3s($page, 25, $show3D3S);
        $showOpenTime = true;
        break;
}
$number = intval(getvar("number"));
if ($number == "")
{
    $number = 1;
}
if ($rs->eof)
{
    $list = "<tr><td colspan=37>目前无{$tblName}相关资料</td></tr>";
}
else if ($gametype == 24)
{
    $list = "<tbody id=\"tbdList\">";
    while (!$rs->eof)
    {
        $n10 = $rs->f['n10'] == 0 - 1 ? "" : $rs->f['n10'];
        $n9 = $rs->f['n9'] == 0 - 1 ? "" : $rs->f['n9'];
        $n8 = $rs->f['n8'] == 0 - 1 ? "" : $rs->f['n8'];
        $n7 = $rs->f['n7'] == 0 - 1 ? "" : $rs->f['n7'];
        $n6 = $rs->f['n6'] == 0 - 1 ? "" : $rs->f['n6'];
        $n5 = $rs->f['n5'] == 0 - 1 ? "" : $rs->f['n5'];
        $n4 = $rs->f['n4'] == 0 - 1 ? "" : $rs->f['n4'];
        $n3 = $rs->f['n3'] == 0 - 1 ? "" : $rs->f['n3'];
        $n2 = $rs->f['n2'] == 0 - 1 ? "" : $rs->f['n2'];
        $n1 = $rs->f['n1'] == 0 - 1 ? "" : $rs->f['n1'];
        $total = $n1 + $n2;
        $openFlag = $MyLotto_5h->checkOpen($rs->f['n3'], $rs->f['n2'], $rs->f['n1'], $rs->f['n4'], $rs->f['n5']);
        if ($showOpenTime)
        {
            $classStr = $ymdhis <= $rs->f['openbet'] && $rs->f['startbet'] <= $ymdhis ? "td6" : "td2";
        }
        else
        {
            $classStr = $rs->f['open'] == date("Y-m-d") ? "td6" : "td2";
        }
        $list .= "<tr class=\"" . $classStr . "\" align=\"center\">";
        $dateNum = date("w", strtotime($rs->f['open']));
        $list .= "<td nowrap>" . $rs->f['round'] . "</td>";
        $list .= "<td style=\"border-left-width:4px;\" nowrap>" . $g_weekname[$dateNum] . "</td>";
        $list .= "<td style=\"border-left-width:4px; border-right-width:4px;\" nowrap>" . $rs->f['open'] . "</td>";
        if ($showOpenTime)
        {
            $openbetIntTemp = strtotime($rs->f['openbet']);
            if (date("Y-m-d", $openbetIntTemp) != $rs->f['open'])
            {
                $list .= "<td nowrap class=\"td14\">";
            }
            else
            {
                $list .= "<td nowrap>";
            }
            $list .= date("H:i", $openbetIntTemp) . "</td>";
        }
        if ($openFlag)
        {
            $list .= "<td><img src=\"image/pk" . $n1 . ".png\"></td>";
            $list .= "<td><img src=\"image/pk" . $n2 . ".png\"></td>";
            $list .= "<td><img src=\"image/pk" . $n3 . ".png\"></td>";
            $list .= "<td><img src=\"image/pk" . $n4 . ".png\"></td>";
            $list .= "<td><img src=\"image/pk" . $n5 . ".png\"></td>";
            $list .= "<td><img src=\"image/pk" . $n6 . ".png\"></td>";
            $list .= "<td><img src=\"image/pk" . $n7 . ".png\"></td>";
            $list .= "<td><img src=\"image/pk" . $n8 . ".png\"></td>";
            $list .= "<td><img src=\"image/pk" . $n9 . ".png\"></td>";
            $list .= "<td><img src=\"image/pk" . $n10 . ".png\"></td>";
            $list .= "<td style=\"border-left-width:4px;\">" . $MyLotto_5h->showText($rs->f["p" . $number], "sd") . "</td>";
            $list .= "<td>" . $MyLotto_5h->showText($rs->f["p" . $number], "bs") . "</td>";
            if ($number <= 5)
            {
                $list .= "<td>" . $MyLotto_5h->showText($rs->f["p" . $number], "animal") . "</td>";
            }
            $list .= "<td nowrap ><font class=text02>" . $MyLotto_5h->showText($rs->f["p11"], "sd") . "</font></td>";
            $list .= "<td nowrap ><font class=text02>" . $MyLotto_5h->showText($rs->f["p11"], "bs") . "</font></td>";
            $list .= "<td nowrap >" . $total . "</td>";
        }
        else
        {
            $list .= "<td style=\"border-left-width:4px;\" colspan=\"41\">&nbsp;</td>";
        }
        $list .= "</tr>";
        $rs->movenext();
    }
    $list .= "</tbody>";
}
else if ($gametype == 20)
{
    $list = "<tbody id=\"tbdList\">";
    while (!$rs->eof)
    {
        $n5 = $rs->f['n5'] == 0 - 1 ? "" : $rs->f['n5'];
        $n4 = $rs->f['n4'] == 0 - 1 ? "" : $rs->f['n4'];
        $n3 = $rs->f['n3'] == 0 - 1 ? "" : $rs->f['n3'];
        $n2 = $rs->f['n2'] == 0 - 1 ? "" : $rs->f['n2'];
        $n1 = $rs->f['n1'] == 0 - 1 ? "" : $rs->f['n1'];
        $openFlag = $MyLotto_5h->checkOpen($rs->f['n3'], $rs->f['n2'], $rs->f['n1'], $rs->f['n4'], $rs->f['n5']);
        if ($showOpenTime)
        {
            $classStr = $ymdhis <= $rs->f['openbet'] && $rs->f['startbet'] <= $ymdhis ? "td6" : "td2";
        }
        else
        {
            $classStr = $rs->f['open'] == date("Y-m-d") ? "td6" : "td2";
        }
        $list .= "<tr class=\"" . $classStr . "\" align=\"center\">";
        $dateNum = date("w", strtotime($rs->f['open']));
        $list .= "<td nowrap>" . $rs->f['round'] . "</td>";
        $list .= "<td style=\"border-left-width:4px;\" nowrap>" . $g_weekname[$dateNum] . "</td>";
        $list .= "<td style=\"border-left-width:4px; border-right-width:4px;\" nowrap>" . $rs->f['open'] . "</td>";
        if ($showOpenTime)
        {
            $openbetIntTemp = strtotime($rs->f['openbet']);
            if (date("Y-m-d", $openbetIntTemp) != $rs->f['open'])
            {
                $list .= "<td nowrap class=\"td14\">";
            }
            else
            {
                $list .= "<td nowrap>";
            }
            $list .= date("H:i", $openbetIntTemp) . "</td>";
        }
        if ($openFlag)
        {
            $list .= "<td style=\"border-left-width:4px;\" nowrap class=\"ball3dBgS2\">" . d2($n1) . "</td>";
            $list .= "<td nowrap class=\"ball3dBgS2\">" . d2($n2) . "</td>";
            $list .= "<td nowrap class=\"ball3dBgS2\">" . d2($n3) . "</td>";
            $list .= "<td nowrap class=\"ball3dBgS2\">" . d2($n4) . "</td>";
            $list .= "<td nowrap style=\"border-right-width:4px;\" class=\"ball3dBgS3\">" . d2($n5) . "</td>";
            $list .= showTable_5($MyLotto_5h->showText($rs->f['p1'], "sd"), $MyLotto_5h->showText($rs->f['p2'], "sd"), $MyLotto_5h->showText($rs->f['p3'], "sd"), $MyLotto_5h->showText($rs->f['p4'], "sd"), $MyLotto_5h->showText($rs->f['p5'], "sd", false));
            $list .= showTable_5($MyLotto_5h->showText($rs->f['p1'], "bs"), $MyLotto_5h->showText($rs->f['p2'], "bs"), $MyLotto_5h->showText($rs->f['p3'], "bs"), $MyLotto_5h->showText($rs->f['p4'], "bs"), $MyLotto_5h->showText($rs->f['p5'], "bs", false));
            $list .= showTable_5($MyLotto_5h->showText($rs->f['p1'], "t_bs"), $MyLotto_5h->showText($rs->f['p2'], "t_bs"), $MyLotto_5h->showText($rs->f['p3'], "t_bs"), $MyLotto_5h->showText($rs->f['p4'], "t_bs"), $MyLotto_5h->showText($rs->f['p5'], "t_bs", false));
            $list .= showTable_5($MyLotto_5h->showText($rs->f['p1'], "s_sd"), $MyLotto_5h->showText($rs->f['p2'], "s_sd"), $MyLotto_5h->showText($rs->f['p3'], "s_sd"), $MyLotto_5h->showText($rs->f['p4'], "s_sd"), $MyLotto_5h->showText($rs->f['p5'], "s_sd", false));
            $list .= showTable_5($MyLotto_5h->showText($rs->f['p1'], "color"), $MyLotto_5h->showText($rs->f['p2'], "color"), $MyLotto_5h->showText($rs->f['p3'], "color"), $MyLotto_5h->showText($rs->f['p4'], "color"), $MyLotto_5h->showText($rs->f['p5'], "color"));
            $list .= showTable_5($MyLotto_5h->showText($rs->f['p1'], "four"), $MyLotto_5h->showText($rs->f['p2'], "four"), $MyLotto_5h->showText($rs->f['p3'], "four"), $MyLotto_5h->showText($rs->f['p4'], "four"), $MyLotto_5h->showText($rs->f['p5'], "four", false));
            $list .= showTable_two_5($MyLotto_5h->showText($rs->f['p6'], "total_sd"), $MyLotto_5h->showText($rs->f['p6'], "total_bs"));
        }
        else
        {
            $list .= "<td style=\"border-left-width:4px;\" colspan=\"41\">&nbsp;</td>";
        }
        $list .= "</tr>";
        $rs->movenext();
    }
    $list .= "</tbody>";
}
else if (20 < $gametype)
{
    $list = "<tbody id=\"tbdList\">";
    while (!$rs->eof)
    {
        $n8 = $rs->f['n8'] == 0 - 1 ? "" : $rs->f['n8'];
        $n7 = $rs->f['n7'] == 0 - 1 ? "" : $rs->f['n7'];
        $n6 = $rs->f['n6'] == 0 - 1 ? "" : $rs->f['n6'];
        $n5 = $rs->f['n5'] == 0 - 1 ? "" : $rs->f['n5'];
        $n4 = $rs->f['n4'] == 0 - 1 ? "" : $rs->f['n4'];
        $n3 = $rs->f['n3'] == 0 - 1 ? "" : $rs->f['n3'];
        $n2 = $rs->f['n2'] == 0 - 1 ? "" : $rs->f['n2'];
        $n1 = $rs->f['n1'] == 0 - 1 ? "" : $rs->f['n1'];
        $total = $n1 + $n2 + $n3 + $n4 + $n5 + $n6 + $n7 + $n8;
        $openFlag = $MyLotto_5h->checkOpen($rs->f['n3'], $rs->f['n2'], $rs->f['n1'], $rs->f['n4'], $rs->f['n5'], $rs->f['n6'], $rs->f['n7'], $rs->f['n8']);
        if ($showOpenTime)
        {
            $classStr = $ymdhis <= $rs->f['openbet'] && $rs->f['startbet'] <= $ymdhis ? "td6" : "td2";
        }
        else
        {
            $classStr = $rs->f['open'] == date("Y-m-d") ? "td6" : "td2";
        }
        $list .= "<tr class=\"" . $classStr . "\" align=\"center\">";
        $dateNum = date("w", strtotime($rs->f['open']));
        $list .= "<td style=\"font-size:15px;\" nowrap>" . $rs->f['round'] . "</td>";
        $list .= "<td style=\"font-size:15px;\" style=\"border-left-width:4px; border-right-width:4px;\" nowrap>" . $rs->f['open'] . "</td>";
        if ($showOpenTime)
        {
            $openbetIntTemp = strtotime($rs->f['openbet']);
            if (date("Y-m-d", $openbetIntTemp) != $rs->f['open'])
            {
                $list .= "<td style=\"font-size:15px;\" nowrap class=\"td14\">";
            }
            else
            {
                $list .= "<td style=\"font-size:15px;\" nowrap>";
            }
            $list .= date("H:i", $openbetIntTemp) . "</td>";
        }
        if ($openFlag)
        {
            $list .= "<td style=\"border-left-width:4px; font-size:15px;\" nowrap class=\"ball_8h_" . ( 18 < $n1 ? "red" : "yellow" ) . "\">" . d2($n1) . "</td>";
            $list .= "<td nowrap class=\"ball_8h_" . ( 18 < $n2 ? "red" : "yellow" ) . "\" style=\"font-size:15px;\">" . d2($n2) . "</td>";
            $list .= "<td nowrap class=\"ball_8h_" . ( 18 < $n3 ? "red" : "yellow" ) . "\" style=\"font-size:15px;\">" . d2($n3) . "</td>";
            $list .= "<td nowrap class=\"ball_8h_" . ( 18 < $n4 ? "red" : "yellow" ) . "\" style=\"font-size:15px;\">" . d2($n4) . "</td>";
            $list .= "<td nowrap class=\"ball_8h_" . ( 18 < $n5 ? "red" : "yellow" ) . "\" style=\"font-size:15px;\">" . d2($n5) . "</td>";
            $list .= "<td nowrap class=\"ball_8h_" . ( 18 < $n6 ? "red" : "yellow" ) . "\" style=\"font-size:15px;\">" . d2($n6) . "</td>";
            $list .= "<td nowrap class=\"ball_8h_" . ( 18 < $n7 ? "red" : "yellow" ) . "\" style=\"font-size:15px;\">" . d2($n7) . "</td>";
            $list .= "<td nowrap class=\"ball_8h_" . ( 18 < $n8 ? "red" : "yellow" ) . "\" style=\"font-size:15px;\">" . d2($n8) . "</td>";
            $list .= show_total_8h($total, $MyLotto_5h->showText($rs->f['p9'], "sd"), $MyLotto_5h->showText($rs->f['p9'], "total_tbsArr"), $MyLotto_5h->showText($rs->f['p9'], "total_8hbs"), $MyLotto_5h->showText($rs->f['p9'], "animal"));
        }
        else
        {
            $list .= "<td style=\"border-left-width:4px;\" colspan=\"18\">&nbsp;</td>";
        }
        $list .= "</tr>";
        $rs->movenext();
    }
    $list .= "</tbody>";
}
$getOpenUrl = $MyLotto_3d->getOpenUrl($gametype);
$btnLink = $getOpenUrl != "" ? "<input type='button' value='官网' class='colorBtn01 clrBrd_{$gametype}' onclick=\"javascript:window.open('{$getOpenUrl}', '_blank')\" />" : "";
if ($gametype == 24)
{
    $tpl3_5 = "result_pk10.htm";
}
else if ($gametype == 20)
{
    $tpl3_5 = "result_5h.htm";
}
else if (20 <= $gametype)
{
    $tpl3_5 = "result_8h.htm";
}
$tpl->load( array("menu" => ($gametype==24?'pk':'ssc')."_menu.htm","main" => $tpl3_5) );
$tpl->set("gametype",$gametype);
$tpl->show( "menu" );

$tpl->set(array ("list" => $list, "button" => $rs->pagelink(), "gametypeStr" => $tblName, "gametype" => "bgClc_{$gametype}", "title_gametype" => " bgImg_{$gametype}", "btnLink" => $btnLink, "checked"));
$tpl->set("play_gametype", $gametype);
$tpl->set("chk" . $number, "checked");
if ($gametype == 24)
{
    if ($number <= 5)
    {
        $colspan = 3;
        $teltlist = "<td width='6%' class=td15 id='bottom-left'>单双</td> <td width='6%' class=td15 id='bottom'>大小</td><td width='6%' class=td15 id='bottom'>龙虎</td>";
    }
    else
    {
        $colspan = 2;
        $teltlist = "<td width='6%' class=td15 id='bottom-left'>单双</td> <td width='6%' class=td15 id='bottom'>大小</td>";
    }
    $tpl->set("colspan", $colspan);
    $tpl->set("td_list", $teltlist);
}
if ($showOpenTime)
{
    $tpl->set(array ("showOpenTimeTd" => "<td width=\"" . ( 20 < $gametype ? "1%" : "1%" ) . "\" style=\"border-bottom-width=4px;\" rowspan=\"2\">开奖<br/>时间</td>", "showOpenTimeTd02" => "<td>&nbsp;</td>", "note3s" => "<div>※开奖时间背景颜色为<span class=\"td14\">粉红色</span>时，代表已过凌晨(开奖日期 = 报表日期加一天)</div>"));
}
$jslink = "<script src=\"core/tpl/k2/jquery-1.4.2.min.js\"></script>\n";
$ui->set("jslink", $jslink);
$ui->set("csscode", ".ball3dBg{font-size:20px;} table td{font-size:16px;}");
$ui->header();
$ui->showNews3D($curruser['acl'],1);
$getOpenUrl = $MyLotto_3d->getOpenUrl($gametype);
echo "<br />";
$tpl->show("main");
$ui->footer();